package com.sz.stock.service;

import com.sz.stock.mapper.EntrustMapper;
import com.sz.stock.mapper.POSMapper;
import com.sz.stock.mapper.StockBuyOrSaleMapper;
import com.sz.stock.model.*;
import org.bouncycastle.asn1.cms.TimeStampedDataParser;
import com.sz.stock.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;


@Service
public class TradingServiceImpl implements ITradingService {

    @Autowired
    private EntrustMapper entrustMapper;

    //1. 存入委托
    @Override
    public ResultBean addEntrust(Entrust entrust, Bankcard bankcard) {

        //获取当前时间
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Timestamp(System.currentTimeMillis()));
        entrust.setStockEntrustTime(time);
        // 备注
        entrust.setStockEntrustStatus("未成交");
        // 成交数量
        entrust.setStockEntrustTransnum(0);
        // 撤销数量
        entrust.setStockEntrustCancelnum(0);
        // 合同编号
        entrust.setStockEntrustContractid("B" + new SimpleDateFormat("yyyMMddHHmmssSSS").format(new Timestamp(System.currentTimeMillis())));
        // 股东账户
        String account = bankcard.getBankCardnumber();
        entrust.setStockEntrustAccount(account);
        // 用户的id
        int userid = entrust.getStockEntrustUserid();
        entrust.setStockEntrustUserid(userid);

        //加入数据库
        int add = entrustMapper.insert(entrust);

        return new ResultBean(1,"成功",entrust.getStockEntrustContractid());
    }

}
